<template>
  <div>
    <!-- 操作区域 -->
    <div class="top-operate clearfix">
      <div class="float-l">
        <el-input @keyup.enter.native="handleSearch" v-model="listQuery.operator" placeholder="操作员姓名" style="width: 300px"></el-input>
        <el-select v-model="listQuery.logType" placeholder="类型" class="pad-l-10">
          <el-option v-for="(val, key) in dict.logType" :key="key" :label="val" :value="key">
          </el-option>
        </el-select>
        <el-date-picker v-model="datePicker"
                        style="margin-left: 10px"
                        type="daterange"
                        unlink-panels
                        range-separator="至"
                        value-format="yyyy-MM-dd HH:mm:ss"
                        :default-time="['00:00:00', '23:59:59']"
                        start-placeholder="开始日期"
                        end-placeholder="结束日期">
        </el-date-picker>
        <el-button type="primary" @click="handleSearch" style="margin-left: 10px">查询</el-button>
      </div>
    </div>
    <!-- 内容列表 -->
    <div class="table-container">
      <el-table :data="listData" v-loading="listLoading"
                element-loading-text="加载中" header-cell-class-name="default-header" row-class-name="default-row"
                style="width: 100%">
        <el-table-column label="操作员" prop="operator" >
        </el-table-column>
        <el-table-column label="操作类型" prop="logType">
          <template slot-scope="scope">
            {{ dict.logType[scope.row.logType] }}
          </template>
        </el-table-column>
        <el-table-column label="操作内容" prop="content">
        </el-table-column>
        <el-table-column label="操作IP" prop="ip" >
        </el-table-column>
        <el-table-column label="操作时间" prop="createTime" >
          <template slot-scope="scope">
            <span>{{scope.row.createTime}}</span>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!-- 列表分页 -->
    <div class="pagination">
      <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange"
                     :current-page="listQuery.currentPage"
                     :page-sizes="[10, 20, 50, 100]" :page-size="listQuery.size"
                     layout="total, sizes, prev, pager, next, jumper"
                     :total="total">
      </el-pagination>
    </div>
  </div>
</template>


<style scoped>

</style>

<script>
  import { getNameByPath } from '@/utils/get-name-by-path' // 不要删除，根据URL获取文件名
  import { pageLog } from '@/api/system/log'

  export default {
    name: getNameByPath(),
    data() {
      return {
        listData: [],
        total: null,
        listLoading: true,
        datePicker: [],
        dict: {},
        listQuery: {
          dateColumn: 'createTime',
          currentPage: 1,
          size: 10,
          keyword: ''
        }
      }
    },
    // 过滤器
    filters: {
      statusFilter(status) {
        const statusMap = {
          1: 'success',
          2: 'danger'
        }
        return statusMap[status]
      }
    },
    // 初始化页面
    created() {
      this.init()
    },
    methods: {
      init() {
        this.listLoading = true
        this.listQuery.enterpriseId = this.getEnterpriseId()
        this.listQuery.startDate = ''
        this.listQuery.endDate = ''
        if (this.datePicker && this.datePicker.length > 0) {
          this.listQuery.startDate = this.datePicker[0]
        }
        if (this.datePicker && this.datePicker.length > 1) {
          this.listQuery.endDate = this.datePicker[1]
        }
        pageLog(this.listQuery).then(response => {
          this.listData = response.data.records
          this.total = response.data.total
          this.dict = response.data.dict
          this.listLoading = false
        })
      },
      handleSearch() {
        this.listQuery.currentPage = 1
        this.init()
      },
      handleSizeChange(val) {
        this.listQuery.size = val
        this.init()
      },
      handleCurrentChange(val) {
        this.listQuery.currentPage = val
        this.init()
      }
    },
    mounted() {
    }
  }
</script>
